<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>等级分布</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
</head>
<body>



<form class="layui-form" action="">



  <div class="layui-form-item">
    <div class="layui-row">
    <div class="layui-col-md2">
        <select name="sid" lay-verify="required" id='server' class="layui-inline">
        <% let is_first=true;%>
        <% for(let k in ret.server ) {%>
            <% if(is_first){%>
            <option value="<%=ret.server[k].sid%>" selected><%=ret.server[k].sname%></option>
            <% is_first=false;%>
            <%}else{%>
            <option value="<%=ret.server[k].sid%>" ><%=ret.server[k].sname%></option>
            <%}%>
        <%}%>
        </select>
    </div>
    <div class="layui-col-md2">
     <button class="layui-btn" lay-submit lay-filter="roleOK">立即提交</button>
    </div>


      
  </div>
  </div>





<!--   <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit lay-filter="roleOK">立即提交</button>
    </div>
  </div> -->
</form>	
<table id="PlogT" lay-filter="PlogT"></table>
<script src="/layui/layui.js"></script>
<script>
layui.config({
    base: '/webui/'  // 模块目录
}).extend({
    "cosjs":"{/}/layui/?name=cosjs",
}).use(['form','table','cosjs','element'], function () {
    let form = layui.form,cosjs=layui.cosjs,$ = layui.jquery;
    let table=layui.table;
    let page=1;
    let total=1;
    let dataRecord;
    function queryPage(_data){
      //向服务器查询
      let index=window.location.pathname.indexOf('/dataDigLv');
      let head=window.location.pathname.slice(0,index);
      let  url =`${head}/dataDigCard/query`;
      cosjs.post(url,_data.field).then(ret=>{
        // for(let i=0;i<ret.ret.length;++i){
        //     ret.ret[i].name=heroConfig[ret.ret[i].id]||ret.ret[i].id;
        //     ret.ret[i].avgLv=(ret.ret[i].lv/ret.ret[i].num).toFixed(1);
        //     ret.ret[i].avgSlv=(ret.ret[i].slv/ret.ret[i].num).toFixed(1);
        //     ret.ret[i].avgBlv=(ret.ret[i].blv/ret.ret[i].num).toFixed(1);
        // }

    

        //table.data=_coll;

        let total=0;
        for(let i=0;i<ret.ret.length;++i){
            total+=ret.ret[i].num;
        }
        for(let i=0;i<ret.ret.length;++i){
            ret.ret[i].rate=((ret.ret[i].num/total)*100).toFixed(0)+'%';
        }

        table.render({
        elem: '#PlogT'
        ,height: 960
        // ,url: '/demo/table/user/' //数据接口
        ,cols: [[ //表头
          {field: 'lv', title: '等级', width:100, sort: true, fixed: 'left'}
          ,{field: 'num', title: '数量', width:100}
          ,{field: 'rate', title: '占比', width:100}
         ]],
        data:ret.ret,
      });

      $('#pageIndex').html(page+'/'+total);
      }).catch(err=>{

        cosjs.alert(err);
      })         
    }

    form.on('submit(roleOK)', function(data){ 
      dataRecord=data;
      dataRecord.field.page=1;
      queryPage(data,page);
      return false;
    })



});
</script>
</body>
</html>